package com.homework.ch06;

public class TestInstanceCounter {
    public static void main(String[] args) {
        // 创建对象前查看计数
        System.out.println("初始实例数: " + InstanceCounter.getInstanceCount());

        // 创建多个对象
        InstanceCounter obj1 = new InstanceCounter();
        InstanceCounter obj2 = new InstanceCounter();
        InstanceCounter obj3 = new InstanceCounter();

        // 随时获取实例化次数
        System.out.println("当前实例数: " + InstanceCounter.getInstanceCount());

        // 再创建一些对象
        new InstanceCounter(); // 不保存引用也可以计数
        new InstanceCounter();

        // 再次获取
        System.out.println("最终实例数: " + InstanceCounter.getInstanceCount());

        // 测试重置功能（可选）
        InstanceCounter.resetCount();
        System.out.println("重置后实例数: " + InstanceCounter.getInstanceCount());

        // 重置后创建新对象
        new InstanceCounter();
        System.out.println("新创建后实例数: " + InstanceCounter.getInstanceCount());
    }
}
